package com.android.demo.widget;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.ScaleAnimation;
import android.view.animation.Transformation;

public class ResizeAnimation extends ScaleAnimation {
	private ViewGroup mViewGroup = null;
	private float mViewHeight = 0.0f;
	
	public ResizeAnimation(ViewGroup v, int nHeight, float fromX, float toX, float fromY, float toY) {
		super(fromX, toX, fromY, toY);
		
		this.mViewGroup = v;
		this.mViewHeight = nHeight;
	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		super.applyTransformation(interpolatedTime, t);
		
		LayoutParams lp = mViewGroup.getLayoutParams();
		lp.height = (int)(mViewHeight * (0.0 + interpolatedTime));
		Log.i("animation", "height: " + lp.height);
		mViewGroup.setLayoutParams(lp);
		
		for (int i=0; i<mViewGroup.getChildCount(); i++){
			if (mViewGroup.getChildAt(i).getVisibility() == View.GONE){
				mViewGroup.getChildAt(i).setVisibility(View.VISIBLE);
			}
		}
	}
}
